package kr.co.dongpang.android;

import android.annotation.TargetApi;
import android.app.Fragment;
import android.app.FragmentManager;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Button;


@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public class SmCartEndFragment extends Fragment {

	public SmCartEndFragment(){
		
	}
	
	
	@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
 
        View rootView = inflater.inflate(R.layout.sm_cart_end, container, false);
        
        String periodText = getArguments().getString("periodText");
        
        
        new  cartEndTask().execute(periodText,null,null);
        
        return rootView;
    }
	
	class cartEndTask extends AsyncTask<String, Void, Void>{

		String period;
		@Override
		protected Void doInBackground(String... params) {
			// TODO Auto-generated method stub
			period = params[0];
			return null;
		}
		
		@Override
		protected void onPostExecute(Void result) {
			((TextView) getActivity().findViewById(R.id.periodText)).setText(period);
			
			((Button) getActivity().findViewById(R.id.end)).setOnClickListener(new View.OnClickListener() {
				
				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					
					   Fragment fragment = null;
					   fragment = new SmMyShoppingFragment(); 
					   FragmentManager fragmentManager = getFragmentManager();
					   fragmentManager.beginTransaction().replace(R.id.frame_container, fragment).commit();					
					
				}
			});
			
			super.onPostExecute(result);
		}
		
	}
	
	
}
